# !/usr/bin/env python
# -*- coding: utf-8 -*-
# ///////////////////////////////////////////////////////////////
# @File    :   getImageBaseData.py
# @Time    :   2024/08/21 14:39:56
# @Author  :   kai.luo
# @Version :   1.0.0
# @Desc    :   获取医疗图片中尾部的公共库
# ///////////////////////////////////////////////////////////////

import re


class ChongqinFooterInfo(object):
    def __init__(self, **kwarg) -> None:
        pass

    def parserFooterData(self, data):
        """_summary_

        Args:
            data (_type_): _description_
        """
        # print(f'parserFooterData---{data}')
        form_footer_list = dict()
        for item in data:
            text = item[1][0]
            if re.findall(r'报\s*告[\u4e00-\u9fff|\u3000-\u303f]{0,2}\：', text.strip()):
                report_time_list = re.findall(
                    r'报告.{0,2}[:：]\s*(\d+\-\d+\-\d{1,2})\s*(\d+[:：]\d+[:：]*\d+)*', text.strip())
                if report_time_list:
                    report_time = report_time_list[0][0]+' '+report_time_list[0][1]
                    form_footer_list.setdefault('报告日期', report_time)
                else:
                    form_footer_list.setdefault('报告日期', '')
            elif '电话：' in text.replace(' ', ''):
                report_tel = re.findall(r'电话[:：]\s*(\+*\d+\-\d+\-*\d*)', text.strip())
                if report_tel:
                    form_footer_list.setdefault('医院电话', report_tel[0])
                else:
                    form_footer_list.setdefault('医院电话', '')
            elif '地址：' in text.replace(' ', ''):
                report_addr = re.findall(r'地址[:：](.*)', text.strip())
                if report_addr:
                    form_footer_list.setdefault('医院地址', report_addr[0].replace(' ', ''))
                else:
                    form_footer_list.setdefault('医院地址', '')
            elif re.findall(r'主\s*检[\u4e00-\u9fff|\u3000-\u303f]{0,1}\：', text.strip()) or re.findall(r'检\s*验[\u4e00-\u9fff|\u3000-\u303f]{0,1}\：', text.strip()):
                report_owner = re.findall(
                    r'检[\u4e00-\u9fff|\u3000-\u303f]{0,3}[:|：]([\u4e00-\u9fff]{2,3})\s', text.strip())
                if report_owner:
                    form_footer_list.setdefault('检验人', report_owner[0])
                else:
                    form_footer_list.setdefault('检验人', '')

                if re.findall(r'审\s*核[\u4e00-\u9fff|\u3000-\u303f]{0,1}\：', text.strip()) or re.findall(r'复\s*核[\u4e00-\u9fff|\u3000-\u303f]{0,1}\：', text.strip()):
                    report_check = re.findall(
                        r'核[\u4e00-\u9fff|\u3000-\u303f]{0,1}[:|：]([\u4e00-\u9fff]{2,3})', text.strip())
                    if report_check:
                        form_footer_list.setdefault('审核人', report_check[0])
                    else:
                        form_footer_list.setdefault('审核人', '')
            elif re.findall(r'审\s*核[\u4e00-\u9fff|\u3000-\u303f]{0,1}\：', text.strip()) or re.findall(r'复\s*核[\u4e00-\u9fff|\u3000-\u303f]{0,1}\：', text.strip()):
                report_check = re.findall(
                    r'核[\u4e00-\u9fff|\u3000-\u303f]{0,1}[:|：]([\u4e00-\u9fff]{2,3})', text.strip())
                if report_check:
                    form_footer_list.setdefault('审核人', report_check[0])
                else:
                    form_footer_list.setdefault('审核人', '')

        return form_footer_list
